{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "L7FxVIIC2JnB"
      },
      "source": [
        "# RGU-IIT CBR Generator"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "QTLNWRnEA-Bx"
      },
      "source": [
        "## Download Import Libraries"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "LYwtxAM92PVT"
      },
      "source": [
        "### Download Libraries"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 1,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "lppp2X5X2RxC",
        "outputId": "981b50c6-a20e-4ccc-9814-92da47d1999d"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "\u001b[?25l     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/284.6 kB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K     \u001b[91m━━━━━━━━━━━━━━━\u001b[0m\u001b[91m╸\u001b[0m\u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m112.6/284.6 kB\u001b[0m \u001b[31m3.2 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K     \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[91m╸\u001b[0m\u001b[90m━\u001b[0m \u001b[32m276.5/284.6 kB\u001b[0m \u001b[31m5.0 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m284.6/284.6 kB\u001b[0m \u001b[31m3.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h  Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m233.4/233.4 kB\u001b[0m \u001b[31m5.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m58.5/58.5 kB\u001b[0m \u001b[31m2.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h  Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m360.5/360.5 kB\u001b[0m \u001b[31m7.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m91.8/91.8 kB\u001b[0m \u001b[31m4.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m200.2/200.2 kB\u001b[0m \u001b[31m5.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h\u001b[33mWARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))': /simple/oslo-config/\u001b[0m\u001b[33m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m67.5/67.5 kB\u001b[0m \u001b[31m2.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m135.5/135.5 kB\u001b[0m \u001b[31m5.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h  Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m208.8/208.8 kB\u001b[0m \u001b[31m2.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h  Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m55.4/55.4 kB\u001b[0m \u001b[31m2.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m225.9/225.9 kB\u001b[0m \u001b[31m8.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m79.1/79.1 kB\u001b[0m \u001b[31m6.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m146.1/146.1 kB\u001b[0m \u001b[31m4.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m94.3/94.3 kB\u001b[0m \u001b[31m8.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h  Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m202.8/202.8 kB\u001b[0m \u001b[31m7.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m89.9/89.9 kB\u001b[0m \u001b[31m6.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m117.0/117.0 kB\u001b[0m \u001b[31m8.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m404.9/404.9 kB\u001b[0m \u001b[31m10.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m214.2/214.2 kB\u001b[0m \u001b[31m9.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m290.7/290.7 kB\u001b[0m \u001b[31m11.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m4.3/4.3 MB\u001b[0m \u001b[31m7.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h  Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m59.6/59.6 kB\u001b[0m \u001b[31m4.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h  Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m138.3/138.3 kB\u001b[0m \u001b[31m8.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h  Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m230.6/230.6 kB\u001b[0m \u001b[31m20.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m226.8/226.8 kB\u001b[0m \u001b[31m11.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m226.0/226.0 kB\u001b[0m \u001b[31m22.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m225.4/225.4 kB\u001b[0m \u001b[31m18.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m225.3/225.3 kB\u001b[0m \u001b[31m18.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m224.5/224.5 kB\u001b[0m \u001b[31m15.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m224.3/224.3 kB\u001b[0m \u001b[31m18.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m212.9/212.9 kB\u001b[0m \u001b[31m6.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m212.3/212.3 kB\u001b[0m \u001b[31m16.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m212.2/212.2 kB\u001b[0m \u001b[31m17.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m212.2/212.2 kB\u001b[0m \u001b[31m17.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m211.9/211.9 kB\u001b[0m \u001b[31m16.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m210.5/210.5 kB\u001b[0m \u001b[31m17.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m210.6/210.6 kB\u001b[0m \u001b[31m19.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m210.6/210.6 kB\u001b[0m \u001b[31m18.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m210.4/210.4 kB\u001b[0m \u001b[31m19.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m210.2/210.2 kB\u001b[0m \u001b[31m18.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m209.8/209.8 kB\u001b[0m \u001b[31m18.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m209.3/209.3 kB\u001b[0m \u001b[31m20.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m210.7/210.7 kB\u001b[0m \u001b[31m18.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m210.4/210.4 kB\u001b[0m \u001b[31m16.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m209.7/209.7 kB\u001b[0m \u001b[31m17.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m209.1/209.1 kB\u001b[0m \u001b[31m14.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m208.7/208.7 kB\u001b[0m \u001b[31m16.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m208.7/208.7 kB\u001b[0m \u001b[31m17.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m208.4/208.4 kB\u001b[0m \u001b[31m16.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m208.2/208.2 kB\u001b[0m \u001b[31m13.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m164.7/164.7 kB\u001b[0m \u001b[31m14.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m164.7/164.7 kB\u001b[0m \u001b[31m14.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m164.5/164.5 kB\u001b[0m \u001b[31m14.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.2/1.2 MB\u001b[0m \u001b[31m24.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h  Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m164.2/164.2 kB\u001b[0m \u001b[31m7.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m164.2/164.2 kB\u001b[0m \u001b[31m7.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m159.6/159.6 kB\u001b[0m \u001b[31m11.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m159.5/159.5 kB\u001b[0m \u001b[31m13.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m159.5/159.5 kB\u001b[0m \u001b[31m14.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m156.6/156.6 kB\u001b[0m \u001b[31m13.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m156.3/156.3 kB\u001b[0m \u001b[31m13.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m155.5/155.5 kB\u001b[0m \u001b[31m13.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m155.1/155.1 kB\u001b[0m \u001b[31m13.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m155.1/155.1 kB\u001b[0m \u001b[31m13.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m159.9/159.9 kB\u001b[0m \u001b[31m15.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.1/1.1 MB\u001b[0m \u001b[31m28.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h  Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n",
            "  Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n",
            "  Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.1/1.1 MB\u001b[0m \u001b[31m34.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h  Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.1/1.1 MB\u001b[0m \u001b[31m38.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h  Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.1/1.1 MB\u001b[0m \u001b[31m43.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h  Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.1/1.1 MB\u001b[0m \u001b[31m34.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h  Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.1/1.1 MB\u001b[0m \u001b[31m44.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h  Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.1/1.1 MB\u001b[0m \u001b[31m46.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h  Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.1/1.1 MB\u001b[0m \u001b[31m37.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h  Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.1/1.1 MB\u001b[0m \u001b[31m33.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h  Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.0/1.0 MB\u001b[0m \u001b[31m38.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h  Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.0/1.0 MB\u001b[0m \u001b[31m44.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h  Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m78.7/78.7 kB\u001b[0m \u001b[31m6.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m307.7/307.7 kB\u001b[0m \u001b[31m23.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m255.8/255.8 kB\u001b[0m \u001b[31m8.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h  Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m470.6/470.6 kB\u001b[0m \u001b[31m33.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m115.0/115.0 kB\u001b[0m \u001b[31m11.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m50.9/50.9 kB\u001b[0m \u001b[31m5.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.3/2.3 MB\u001b[0m \u001b[31m54.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m918.6/918.6 kB\u001b[0m \u001b[31m48.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h  Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m127.9/127.9 kB\u001b[0m \u001b[31m14.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h  \u001b[1;31merror\u001b[0m: \u001b[1msubprocess-exited-with-error\u001b[0m\n",
            "  \n",
            "  \u001b[31m×\u001b[0m \u001b[32mpython setup.py egg_info\u001b[0m did not run successfully.\n",
            "  \u001b[31m│\u001b[0m exit code: \u001b[1;36m1\u001b[0m\n",
            "  \u001b[31m╰─>\u001b[0m See above for output.\n",
            "  \n",
            "  \u001b[1;35mnote\u001b[0m: This error originates from a subprocess, and is likely not a problem with pip.\n",
            "  Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25herror\n",
            "\u001b[1;31merror\u001b[0m: \u001b[1mmetadata-generation-failed\u001b[0m\n",
            "\n",
            "\u001b[31m×\u001b[0m Encountered error while generating package metadata.\n",
            "\u001b[31m╰─>\u001b[0m See above for output.\n",
            "\n",
            "\u001b[1;35mnote\u001b[0m: This is an issue with the package mentioned above, not pip.\n",
            "\u001b[1;36mhint\u001b[0m: See above for details.\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m75.0/75.0 kB\u001b[0m \u001b[31m1.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m144.8/144.8 kB\u001b[0m \u001b[31m8.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m77.9/77.9 kB\u001b[0m \u001b[31m6.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m58.3/58.3 kB\u001b[0m \u001b[31m5.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25hCollecting datasets\n",
            "  Downloading datasets-2.18.0-py3-none-any.whl (510 kB)\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m510.5/510.5 kB\u001b[0m \u001b[31m8.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25hRequirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from datasets) (3.13.3)\n",
            "Requirement already satisfied: numpy>=1.17 in /usr/local/lib/python3.10/dist-packages (from datasets) (1.25.2)\n",
            "Requirement already satisfied: pyarrow>=12.0.0 in /usr/local/lib/python3.10/dist-packages (from datasets) (14.0.2)\n",
            "Requirement already satisfied: pyarrow-hotfix in /usr/local/lib/python3.10/dist-packages (from datasets) (0.6)\n",
            "Collecting dill<0.3.9,>=0.3.0 (from datasets)\n",
            "  Downloading dill-0.3.8-py3-none-any.whl (116 kB)\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m116.3/116.3 kB\u001b[0m \u001b[31m13.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25hRequirement already satisfied: pandas in /usr/local/lib/python3.10/dist-packages (from datasets) (1.5.3)\n",
            "Requirement already satisfied: requests>=2.19.0 in /usr/local/lib/python3.10/dist-packages (from datasets) (2.31.0)\n",
            "Requirement already satisfied: tqdm>=4.62.1 in /usr/local/lib/python3.10/dist-packages (from datasets) (4.66.2)\n",
            "Collecting xxhash (from datasets)\n",
            "  Downloading xxhash-3.4.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (194 kB)\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m194.1/194.1 kB\u001b[0m \u001b[31m19.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25hCollecting multiprocess (from datasets)\n",
            "  Downloading multiprocess-0.70.16-py310-none-any.whl (134 kB)\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m134.8/134.8 kB\u001b[0m \u001b[31m15.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25hRequirement already satisfied: fsspec[http]<=2024.2.0,>=2023.1.0 in /usr/local/lib/python3.10/dist-packages (from datasets) (2023.6.0)\n",
            "Requirement already satisfied: aiohttp in /usr/local/lib/python3.10/dist-packages (from datasets) (3.9.3)\n",
            "Requirement already satisfied: huggingface-hub>=0.19.4 in /usr/local/lib/python3.10/dist-packages (from datasets) (0.20.3)\n",
            "Requirement already satisfied: packaging in /usr/local/lib/python3.10/dist-packages (from datasets) (24.0)\n",
            "Requirement already satisfied: pyyaml>=5.1 in /usr/local/lib/python3.10/dist-packages (from datasets) (6.0.1)\n",
            "Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.10/dist-packages (from aiohttp->datasets) (1.3.1)\n",
            "Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->datasets) (23.2.0)\n",
            "Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from aiohttp->datasets) (1.4.1)\n",
            "Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.10/dist-packages (from aiohttp->datasets) (6.0.5)\n",
            "Requirement already satisfied: yarl<2.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->datasets) (1.9.4)\n",
            "Requirement already satisfied: async-timeout<5.0,>=4.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp->datasets) (4.0.3)\n",
            "Requirement already satisfied: typing-extensions>=3.7.4.3 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.19.4->datasets) (4.10.0)\n",
            "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests>=2.19.0->datasets) (3.3.2)\n",
            "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests>=2.19.0->datasets) (3.6)\n",
            "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests>=2.19.0->datasets) (2.0.7)\n",
            "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests>=2.19.0->datasets) (2024.2.2)\n",
            "Requirement already satisfied: python-dateutil>=2.8.1 in /usr/local/lib/python3.10/dist-packages (from pandas->datasets) (2.8.2)\n",
            "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas->datasets) (2023.4)\n",
            "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.8.1->pandas->datasets) (1.16.0)\n",
            "Installing collected packages: xxhash, dill, multiprocess, datasets\n",
            "Successfully installed datasets-2.18.0 dill-0.3.8 multiprocess-0.70.16 xxhash-3.4.1\n"
          ]
        }
      ],
      "source": [
        "!pip install mistral -q\n",
        "!pip install mistralai -q\n",
        "!pip install datasets"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "2wLXcWkp2Txq"
      },
      "source": [
        "### Import Libraries"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "kvNct0THzypY"
      },
      "outputs": [],
      "source": [
        "from tqdm import tqdm\n",
        "from typing import *\n",
        "from datasets import load_dataset, Dataset, DatasetDict\n",
        "from tqdm import tqdm\n",
        "from sklearn.metrics.pairwise import cosine_similarity\n",
        "from mistralai.client import MistralClient\n",
        "from mistralai.models.chat_completion import ChatMessage\n",
        "\n",
        "import numpy as np\n",
        "import requests\n",
        "import pandas as pd\n",
        "import json\n",
        "import numpy as np\n",
        "import pandas as pd\n",
        "import time"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "y3G0h1XvIxup"
      },
      "source": [
        "## Mistral AI setup"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "ncg8EkIyIzcF"
      },
      "outputs": [],
      "source": [
        "api_key = \"XXX\"\n",
        "model = \"open-mistral-7b\"\n",
        "client = MistralClient(api_key=api_key)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "r_5BbtAtZvsz"
      },
      "source": [
        "## CBR system with Similarity Indexers"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "Tq4qlSrkZw74"
      },
      "outputs": [],
      "source": [
        "class Case:\n",
        "    def __init__(self, index, question, matching_question_embeddings, text, retrieval_text_embeddings, keywords, retrieval_keywords_embeddings, answer):\n",
        "        self.index = index\n",
        "        self.question = question\n",
        "        self.matching_question_embeddings = np.array(eval(matching_question_embeddings))\n",
        "        self.text = text\n",
        "        self.retrieval_text_embeddings = np.array(eval(retrieval_text_embeddings))\n",
        "        self.keywords = keywords\n",
        "        self.retrieval_keywords_embeddings = np.array(eval(retrieval_keywords_embeddings))\n",
        "        self.answer = answer\n",
        "\n",
        "case_database = []\n",
        "\n",
        "class CbrSystem:\n",
        "    def __init__(self, cases):\n",
        "        self.cases = cases\n",
        "        self.global_matching_question_embeddings = []\n",
        "        self.global_retrieval_text_embeddings = []\n",
        "        self.global_retrieval_keyword_embeddings = []\n",
        "        cases = cases\n",
        "        for case in self.cases:\n",
        "            self.global_matching_question_embeddings.append(case.matching_question_embeddings)\n",
        "            self.global_retrieval_text_embeddings.append(case.retrieval_text_embeddings)\n",
        "            self.global_retrieval_keyword_embeddings.append(case.retrieval_keywords_embeddings)\n",
        "\n",
        "    def retrieve_matches(self, matching_query_embeddings, retrieval_query_embeddings, document_count, question_weight, snippet_weight, keywords_weight):\n",
        "        question_similarities = np.zeros(len(self.cases))\n",
        "        snippet_similarities = np.zeros(len(self.cases))\n",
        "        keyword_similarities = np.zeros(len(self.cases))\n",
        "\n",
        "        if question_weight > 0:\n",
        "            question_similarities = np.array([cosine_similarity([matching_query_embeddings], [matching_question_embedding])[0][0] for matching_question_embedding in self.global_matching_question_embeddings])\n",
        "        if snippet_weight > 0:\n",
        "            snippet_similarities = np.array([cosine_similarity([retrieval_query_embeddings], [retrieval_text_embeddings])[0][0] for retrieval_text_embeddings in self.global_retrieval_text_embeddings])\n",
        "        if keywords_weight > 0:\n",
        "            keyword_similarities = np.array([cosine_similarity([retrieval_query_embeddings], [retrieval_keyword_embeddings])[0][0] for retrieval_keyword_embeddings in self.global_retrieval_keyword_embeddings])\n",
        "\n",
        "        combined_similarities = (question_weight * np.array(question_similarities)) + (snippet_weight * np.array(snippet_similarities)) + (keywords_weight * np.array(keyword_similarities))\n",
        "        closest_case_indices = np.argsort(combined_similarities)[-document_count:][::-1]\n",
        "\n",
        "        results = [self.cases[index] for index in closest_case_indices]\n",
        "        return results, closest_case_indices"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "xpsXxadvuEdq"
      },
      "source": [
        "## Load Assets from Pre-Built Sources"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "7nneQCDcMbWv",
        "outputId": "ea90a1b2-5654-4486-affb-2b367e9d7a52"
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "Index(['question', 'answer', 'snippet', 'snippet_sentences', 'keywords',\n",
              "       '__index_level_0__', 'referenced_acts',\n",
              "       'question_normal_bert_matching_embeddings',\n",
              "       'question_legal_bert_matching_embeddings',\n",
              "       'question_angle_bert_matching_embeddings',\n",
              "       'question_normal_bert_retrieval_embeddings',\n",
              "       'question_legal_bert_retrieval_embeddings',\n",
              "       'question_angle_bert_retrieval_embeddings',\n",
              "       'answer_normal_bert_matching_embeddings',\n",
              "       'answer_legal_bert_matching_embeddings',\n",
              "       'answer_angle_bert_matching_embeddings',\n",
              "       'answer_normal_bert_retrieval_embeddings',\n",
              "       'answer_legal_bert_retrieval_embeddings',\n",
              "       'answer_angle_bert_retrieval_embeddings',\n",
              "       'keyword_normal_bert_matching_embeddings',\n",
              "       'keyword_legal_bert_matching_embeddings',\n",
              "       'keyword_angle_bert_matching_embeddings',\n",
              "       'keyword_normal_bert_retrieval_embeddings',\n",
              "       'keyword_legal_bert_retrieval_embeddings',\n",
              "       'keyword_angle_bert_retrieval_embeddings',\n",
              "       'snippet_normal_bert_matching_embeddings',\n",
              "       'snippet_legal_bert_matching_embeddings',\n",
              "       'snippet_angle_bert_matching_embeddings',\n",
              "       'snippet_normal_bert_retrieval_embeddings',\n",
              "       'snippet_legal_bert_retrieval_embeddings',\n",
              "       'snippet_angle_bert_retrieval_embeddings'],\n",
              "      dtype='object')"
            ]
          },
          "execution_count": 9,
          "metadata": {},
          "output_type": "execute_result"
        }
      ],
      "source": [
        "pd.read_csv(\"resources/cbr_dataset_embeddings.csv\").columns"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "PbEI2FtbMXSx",
        "outputId": "83af26f9-1fc8-401e-a594-553bd532d742"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "2084\n"
          ]
        }
      ],
      "source": [
        "df = pd.read_csv(\"resources/cbr_dataset_embeddings.csv\")\n",
        "selected_columns = [\n",
        "                    'question', 'answer', 'snippet', 'keywords',\n",
        "                    'question_normal_bert_matching_embeddings',\n",
        "                    'question_legal_bert_matching_embeddings',\n",
        "                    'question_angle_bert_matching_embeddings',\n",
        "                    'question_normal_bert_retrieval_embeddings',\n",
        "                    'question_legal_bert_retrieval_embeddings',\n",
        "                    'question_angle_bert_retrieval_embeddings',\n",
        "                    'answer_normal_bert_matching_embeddings',\n",
        "                    'answer_legal_bert_matching_embeddings',\n",
        "                    'answer_angle_bert_matching_embeddings',\n",
        "                    'answer_normal_bert_retrieval_embeddings',\n",
        "                    'answer_legal_bert_retrieval_embeddings',\n",
        "                    'answer_angle_bert_retrieval_embeddings',\n",
        "                    'keyword_normal_bert_matching_embeddings',\n",
        "                    'keyword_legal_bert_matching_embeddings',\n",
        "                    'keyword_angle_bert_matching_embeddings',\n",
        "                    'keyword_normal_bert_retrieval_embeddings',\n",
        "                    'keyword_legal_bert_retrieval_embeddings',\n",
        "                    'keyword_angle_bert_retrieval_embeddings',\n",
        "                    'snippet_normal_bert_matching_embeddings',\n",
        "                    'snippet_legal_bert_matching_embeddings',\n",
        "                    'snippet_angle_bert_matching_embeddings',\n",
        "                    'snippet_normal_bert_retrieval_embeddings',\n",
        "                    'snippet_legal_bert_retrieval_embeddings',\n",
        "                    'snippet_angle_bert_retrieval_embeddings'\n",
        "                    ]\n",
        "main_df = df.loc[:, selected_columns].drop_duplicates(subset='question').reset_index(drop=True)\n",
        "print(len(main_df))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "nvwFKNMDM7U3"
      },
      "outputs": [],
      "source": [
        "cases_normal_bert = []\n",
        "cases_legal_bert = []\n",
        "cases_angle_bert = []"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "kLttAbT7uHUk",
        "outputId": "14f1a967-8f47-4b6c-f299-38cf9237bf74"
      },
      "outputs": [
        {
          "name": "stderr",
          "output_type": "stream",
          "text": [
            "2084it [01:34, 22.12it/s]\n"
          ]
        }
      ],
      "source": [
        "for index, row in tqdm(main_df.iterrows()):\n",
        "  cases_normal_bert.append(Case(index, row['question'], row['question_normal_bert_matching_embeddings'], row['snippet'], row['snippet_normal_bert_retrieval_embeddings'], row['keywords'], row['keyword_normal_bert_retrieval_embeddings'], row['answer']))\n",
        "  cases_legal_bert.append(Case(index, row['question'], row['question_legal_bert_matching_embeddings'], row['snippet'], row['snippet_legal_bert_retrieval_embeddings'], row['keywords'], row['keyword_legal_bert_retrieval_embeddings'], row['answer']))\n",
        "  cases_angle_bert.append(Case(index, row['question'], row['question_angle_bert_matching_embeddings'], row['snippet'], row['snippet_angle_bert_retrieval_embeddings'], row['keywords'], row['keyword_angle_bert_retrieval_embeddings'], row['answer']))\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "x4AOjda-2r6d",
        "outputId": "9242671e-36d7-4154-8ba2-8f2f3ad07225"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "2084\n",
            "2084\n",
            "2084\n"
          ]
        }
      ],
      "source": [
        "print(len(cases_normal_bert))\n",
        "print(len(cases_legal_bert))\n",
        "print(len(cases_angle_bert))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "LbEpGnWNOMzA",
        "outputId": "3c09a3b1-aa9c-46a3-fa6e-6f14ca67c3ae"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "\n",
            " Cases loaded into the systems\n"
          ]
        }
      ],
      "source": [
        "normal_bert_cbr_system = CbrSystem(cases_normal_bert)\n",
        "legal_bert_cbr_system = CbrSystem(cases_legal_bert)\n",
        "angle_bert_cbr_system = CbrSystem(cases_angle_bert)\n",
        "\n",
        "print('\\n Cases loaded into the systems');"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "MEuJ_kLiI5UT"
      },
      "source": [
        "## Mistral Inference Component"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "oJXBblISI8B-"
      },
      "outputs": [],
      "source": [
        "def get_mistral_response(request):\n",
        "  time.sleep(0.5)\n",
        "  messages = [\n",
        "      ChatMessage(role=\"user\", content=request)\n",
        "  ]\n",
        "\n",
        "  chat_response = client.chat(\n",
        "      model=model,\n",
        "      messages=messages,\n",
        "  )\n",
        "\n",
        "  return chat_response.choices[0].message.content"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Gow3SDIjn9RN"
      },
      "source": [
        "## Algorithms"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "IuJ9NW0mn-ha"
      },
      "outputs": [],
      "source": [
        "def execute_pipeline_no_rag(question, is_simulation=False):\n",
        "  response = get_mistral_response(question)\n",
        "  if (is_simulation):\n",
        "    return None\n",
        "  return response\n",
        "\n",
        "def execute_pipeline_x_snippet(cbr_system, question, question_matching_embeddings, question_retrieval_embeddings, k, w1, w2, w3, is_simulation=False):\n",
        "    matched_cases, indexes = cbr_system.retrieve_matches(np.array(eval(question_matching_embeddings)), np.array(eval(question_retrieval_embeddings)), k, w1, w2, w3)\n",
        "    if (is_simulation):\n",
        "        return None, None, indexes\n",
        "    matched_case_string = ['\"' + matched_case.text + '\"' for matched_case in matched_cases]\n",
        "    context = ' | '.join(matched_case_string)\n",
        "    response = get_mistral_response('Answer \"' + question + '\" by using the following contexts: { ' + context + ' }')\n",
        "    return response, context, indexes\n",
        "\n",
        "def execute_pipeline_x_case(cbr_system, question, question_matching_embeddings, question_retrieval_embeddings, k, w1, w2, w3, is_simulation=False):\n",
        "    matched_cases, indexes = cbr_system.retrieve_matches(np.array(eval(question_matching_embeddings)), np.array(eval(question_retrieval_embeddings)), k, w1, w2, w3)\n",
        "    if (is_simulation):\n",
        "        return None, None, indexes\n",
        "    matched_case_string = ['\"Question: \"' + matched_case.question + '\", citation: \"' + matched_case.text + '\" and \" answer: \"' + matched_case.answer + '\"' for matched_case in matched_cases]\n",
        "    context = ' | '.join(matched_case_string)\n",
        "    response = get_mistral_response('Answer \"' + question + '\" as a simple string (with no structure) by using the following question, citation and answer tuples as context: { ' + context + ' }')\n",
        "    return response, context, indexes"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "LFKtoEUTJ7vP"
      },
      "source": [
        "# Run - Mistral generation tests"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "49eJCtokHWjA",
        "outputId": "33f42c90-c320-4e39-b595-ba08a5946df2"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "35\n"
          ]
        }
      ],
      "source": [
        "k = 2084\n",
        "df_test = pd.read_csv(\"resources/test_dataset_embeddings.csv\")\n",
        "print(len(df_test))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "r-qSoHo2KNS2"
      },
      "outputs": [],
      "source": [
        "new_df = pd.DataFrame(columns=['case_index','no_rag_pipeline_result','normal_bert_hybrid_snippet_k1_indexes','normal_bert_hybrid_snippet_k1_context','normal_bert_hybrid_snippet_k1_result','normal_bert_hybrid_case_k1_indexes','normal_bert_hybrid_case_k1_context','normal_bert_hybrid_case_k1_result','legal_bert_hybrid_snippet_k1_indexes','legal_bert_hybrid_snippet_k1_context','legal_bert_hybrid_snippet_k1_result','legal_bert_hybrid_case_k1_indexes','legal_bert_hybrid_case_k1_context','legal_bert_hybrid_case_k1_result','angle_bert_hybrid_snippet_k1_indexes','angle_bert_hybrid_snippet_k1_context','angle_bert_hybrid_snippet_k1_result','angle_bert_hybrid_case_k1_indexes','angle_bert_hybrid_case_k1_context','angle_bert_hybrid_case_k1_result','normal_bert_hybrid_snippet_k3_indexes','normal_bert_hybrid_snippet_k3_context','normal_bert_hybrid_snippet_k3_result','normal_bert_hybrid_case_k3_indexes','normal_bert_hybrid_case_k3_context','normal_bert_hybrid_case_k3_result','legal_bert_hybrid_snippet_k3_indexes','legal_bert_hybrid_snippet_k3_context','legal_bert_hybrid_snippet_k3_result','legal_bert_hybrid_case_k3_indexes','legal_bert_hybrid_case_k3_context','legal_bert_hybrid_case_k3_result','angle_bert_hybrid_snippet_k3_indexes','angle_bert_hybrid_snippet_k3_context','angle_bert_hybrid_snippet_k3_result','angle_bert_hybrid_case_k3_indexes','angle_bert_hybrid_case_k3_context','angle_bert_hybrid_case_k3_result'])\n",
        "\n",
        "i = 0\n",
        "for index, row in df_test.iterrows():\n",
        "    row['case_index'] = index\n",
        "\n",
        "    # k = 0\n",
        "    no_rag_pipeline_result = execute_pipeline_no_rag(row['question'])\n",
        "    row['no_rag_pipeline_result'] = no_rag_pipeline_result\n",
        "\n",
        "    # k = 1\n",
        "    normal_bert_hybrid_snippet_k1_result, normal_bert_hybrid_snippet_k1_context, normal_bert_hybrid_snippet_k1_indexes = execute_pipeline_x_snippet(normal_bert_cbr_system, row['question'], row['question_normal_bert_matching_embeddings'], row['question_normal_bert_retrieval_embeddings'], 1, 0.25, 0.4, 0.35)\n",
        "    row['normal_bert_hybrid_snippet_k1_indexes'] = normal_bert_hybrid_snippet_k1_indexes\n",
        "    row['normal_bert_hybrid_snippet_k1_context'] = normal_bert_hybrid_snippet_k1_context\n",
        "    row['normal_bert_hybrid_snippet_k1_result'] = normal_bert_hybrid_snippet_k1_result\n",
        "    normal_bert_hybrid_case_k1_result, normal_bert_hybrid_case_k1_context, normal_bert_hybrid_k1_indexes = execute_pipeline_x_case(normal_bert_cbr_system, row['question'], row['question_normal_bert_matching_embeddings'], row['question_normal_bert_retrieval_embeddings'], 1, 0.25, 0.4, 0.35)\n",
        "    row['normal_bert_hybrid_case_k1_indexes'] = normal_bert_hybrid_k1_indexes\n",
        "    row['normal_bert_hybrid_case_k1_context'] = normal_bert_hybrid_case_k1_context\n",
        "    row['normal_bert_hybrid_case_k1_result'] = normal_bert_hybrid_case_k1_result\n",
        "    legal_bert_hybrid_snippet_k1_result, legal_bert_hybrid_snippet_k1_context, legal_bert_hybrid_snippet_k1_indexes = execute_pipeline_x_snippet(legal_bert_cbr_system, row['question'], row['question_legal_bert_matching_embeddings'], row['question_legal_bert_retrieval_embeddings'], 1, 0.25, 0.4, 0.35)\n",
        "    row['legal_bert_hybrid_snippet_k1_indexes'] = legal_bert_hybrid_snippet_k1_indexes\n",
        "    row['legal_bert_hybrid_snippet_k1_context'] = legal_bert_hybrid_snippet_k1_context\n",
        "    row['legal_bert_hybrid_snippet_k1_result'] = legal_bert_hybrid_snippet_k1_result\n",
        "    legal_bert_hybrid_case_k1_result, legal_bert_hybrid_case_k1_context, legal_bert_hybrid_k1_indexes = execute_pipeline_x_case(legal_bert_cbr_system, row['question'], row['question_legal_bert_matching_embeddings'], row['question_legal_bert_retrieval_embeddings'], 1, 0.25, 0.4, 0.35)\n",
        "    row['legal_bert_hybrid_case_k1_indexes'] = legal_bert_hybrid_k1_indexes\n",
        "    row['legal_bert_hybrid_case_k1_context'] = legal_bert_hybrid_case_k1_context\n",
        "    row['legal_bert_hybrid_case_k1_result'] = legal_bert_hybrid_case_k1_result\n",
        "    angle_bert_hybrid_snippet_k1_result, angle_bert_hybrid_snippet_k1_context, angle_bert_hybrid_snippet_k1_indexes = execute_pipeline_x_snippet(angle_bert_cbr_system, row['question'], row['question_angle_bert_matching_embeddings'], row['question_angle_bert_retrieval_embeddings'], 1, 0.25, 0.4, 0.35)\n",
        "    row['angle_bert_hybrid_snippet_k1_indexes'] = angle_bert_hybrid_snippet_k1_indexes\n",
        "    row['angle_bert_hybrid_snippet_k1_context'] = angle_bert_hybrid_snippet_k1_context\n",
        "    row['angle_bert_hybrid_snippet_k1_result'] = angle_bert_hybrid_snippet_k1_result\n",
        "    angle_bert_hybrid_case_k1_result, angle_bert_hybrid_case_k1_context, angle_bert_hybrid_k1_indexes = execute_pipeline_x_case(angle_bert_cbr_system, row['question'], row['question_angle_bert_matching_embeddings'], row['question_angle_bert_retrieval_embeddings'], 1, 0.25, 0.4, 0.35)\n",
        "    row['angle_bert_hybrid_case_k1_indexes'] = angle_bert_hybrid_k1_indexes\n",
        "    row['angle_bert_hybrid_case_k1_context'] = angle_bert_hybrid_case_k1_context\n",
        "    row['angle_bert_hybrid_case_k1_result'] = angle_bert_hybrid_case_k1_result\n",
        "\n",
        "    # k = 3\n",
        "    normal_bert_hybrid_snippet_k3_result, normal_bert_hybrid_snippet_k3_context, normal_bert_hybrid_snippet_k3_indexes = execute_pipeline_x_snippet(normal_bert_cbr_system, row['question'], row['question_normal_bert_matching_embeddings'], row['question_normal_bert_retrieval_embeddings'], 3, 0.25, 0.4, 0.35)\n",
        "    row['normal_bert_hybrid_snippet_k3_indexes'] = normal_bert_hybrid_snippet_k3_indexes\n",
        "    row['normal_bert_hybrid_snippet_k3_context'] = normal_bert_hybrid_snippet_k3_context\n",
        "    row['normal_bert_hybrid_snippet_k3_result'] = normal_bert_hybrid_snippet_k3_result\n",
        "    normal_bert_hybrid_k3_case_result, normal_bert_hybrid_k3_case_context, normal_bert_hybrid_k3_indexes = execute_pipeline_x_case(normal_bert_cbr_system, row['question'], row['question_normal_bert_matching_embeddings'], row['question_normal_bert_retrieval_embeddings'], 3, 0.25, 0.4, 0.35)\n",
        "    row['normal_bert_hybrid_case_k3_indexes'] = normal_bert_hybrid_k3_indexes\n",
        "    row['normal_bert_hybrid_case_k3_context'] = normal_bert_hybrid_k3_case_context\n",
        "    row['normal_bert_hybrid_case_k3_result'] = normal_bert_hybrid_k3_case_result\n",
        "    legal_bert_hybrid_snippet_k3_result, legal_bert_hybrid_snippet_k3_context, legal_bert_hybrid_snippet_k3_indexes = execute_pipeline_x_snippet(legal_bert_cbr_system, row['question'], row['question_legal_bert_matching_embeddings'], row['question_legal_bert_retrieval_embeddings'], 3, 0.25, 0.4, 0.35)\n",
        "    row['legal_bert_hybrid_snippet_k3_indexes'] = legal_bert_hybrid_snippet_k3_indexes\n",
        "    row['legal_bert_hybrid_snippet_k3_context'] = legal_bert_hybrid_snippet_k3_context\n",
        "    row['legal_bert_hybrid_snippet_k3_result'] = legal_bert_hybrid_snippet_k3_result\n",
        "    legal_bert_hybrid_case_k3_result, legal_bert_hybrid_case_k3_context, legal_bert_hybrid_indexes = execute_pipeline_x_case(legal_bert_cbr_system, row['question'], row['question_legal_bert_matching_embeddings'], row['question_legal_bert_retrieval_embeddings'], 3, 0.25, 0.4, 0.35)\n",
        "    row['legal_bert_hybrid_case_k3_indexes'] = legal_bert_hybrid_indexes\n",
        "    row['legal_bert_hybrid_case_k3_context'] = legal_bert_hybrid_case_k3_context\n",
        "    row['legal_bert_hybrid_case_k3_result'] = legal_bert_hybrid_case_k3_result\n",
        "    angle_bert_hybrid_snippet_k3_result, angle_bert_hybrid_snippet_k3_context, angle_bert_hybrid_snippet_k3_indexes = execute_pipeline_x_snippet(angle_bert_cbr_system, row['question'], row['question_angle_bert_matching_embeddings'], row['question_angle_bert_retrieval_embeddings'], 3, 0.25, 0.4, 0.35)\n",
        "    row['angle_bert_hybrid_snippet_k3_indexes'] = angle_bert_hybrid_snippet_k3_indexes\n",
        "    row['angle_bert_hybrid_snippet_k3_context'] = angle_bert_hybrid_snippet_k3_context\n",
        "    row['angle_bert_hybrid_snippet_k3_result'] = angle_bert_hybrid_snippet_k3_result\n",
        "    angle_bert_hybrid_case_k3_result, angle_bert_hybrid_case_k3_context, angle_bert_hybrid_indexes = execute_pipeline_x_case(angle_bert_cbr_system, row['question'], row['question_angle_bert_matching_embeddings'], row['question_angle_bert_retrieval_embeddings'], 3, 0.25, 0.4, 0.35)\n",
        "    row['angle_bert_hybrid_case_k3_indexes'] = angle_bert_hybrid_indexes\n",
        "    row['angle_bert_hybrid_case_k3_context'] = angle_bert_hybrid_case_k3_context\n",
        "    row['angle_bert_hybrid_case_k3_result'] = angle_bert_hybrid_case_k3_result\n",
        "\n",
        "    new_df = new_df.append(row)\n",
        "\n",
        "    i = i + 1\n",
        "    print(i)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "43VHeFnTR9Nb"
      },
      "outputs": [],
      "source": [
        "new_df"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "WWJQqjG6H2ZN"
      },
      "outputs": [],
      "source": [
        "!huggingface-cli login --token XXX\n",
        "new_df.reset_index(drop=True, inplace=True)\n",
        "\n",
        "output_dataset = DatasetDict({'w025w040w035': Dataset.from_pandas(new_df)})\n",
        "output_dataset.push_to_hub('XXX')"
      ]
    }
  ],
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}
